package com.adrian.misc.fractal;

import java.awt.Point;

import com.adrian.misc.fractal.math.ComplexNumber;
import com.adrian.misc.fractal.math.RectArea;

public class AreaMapping {
	RectArea mathMap;

	Integer xStart = 0;

	Integer yStart = 0;

	Integer width = 0;

	Integer height = 0;

	public AreaMapping(RectArea ra, Point pStart, int pWidth, int pHeight) {
		mathMap = ra;
		xStart = pStart.x;
		yStart = pStart.y;
		width = pWidth;
		height = pHeight;
	}

	// @ TODO remove
	/*
	 * public AreaMapping(RectArea ra, Point pStart) { mathMap = ra; xStart =
	 * pStart.x; yStart = pStart.y; }
	 */
	public AreaMapping(RectArea ra, int pWidth, int pHeight) {
		mathMap = ra;
		width = pWidth;
		height = pHeight;
	}

	public AreaMapping(RectArea ra) {
		mathMap = ra;
	}
	
	public AreaMapping(AreaMapping am) {
		mathMap = new RectArea(am.mathMap);
		width = am.width.intValue();
		height = am.height.intValue();
		xStart = am.xStart.intValue();
		yStart = am.yStart.intValue();
	}
	public ComplexNumber getCCoord(int x, int y) {
		return new ComplexNumber(((x - xStart) / width) * mathMap.width
				+ mathMap.cStart.X, mathMap.cStart.Y - ((y - yStart) / height)
				* mathMap.height);
	}

	public void getCCoord(int x, int y, ComplexNumber c) {
		c.X = ((double) (x - xStart) / (double) width) * mathMap.width
				+ mathMap.cStart.X;
		c.Y = mathMap.cStart.Y - ((double) (y - yStart) / (double) height)
				* mathMap.height;
	}

	@Override
	public String toString() {
		return "AreaMap: xs,ys,w,h,mathMap {" + xStart + "," + yStart + ","
				+ width + "," + height + " " + mathMap + "}";
	}

}
